////
////  NSString-Helper.m
////  HHBank
////
////  Created by 杨帅 on 11-9-4.
////  Copyright 2011 __MyCompanyName__. All rights reserved.
////
//
#import "NSString-Helper.h"
@implementation NSString (Helpers)

//TODO: 纯数字
+ (BOOL) isNumber:(NSString *)aString{
	if([aString length] == 0)
		return NO;

	for(int i=0;i<[aString length];i++)
	{
		char aa = [aString characterAtIndex:i];
		if(!(aa>= '0' && aa<= '9'))
		{
			///有非数字
			return NO;
		}
	}
	
	return YES;
}
//
//TODO: 判断是否电话号码
+ (BOOL) isPhoneNumber:(NSString *)aString{
	//0-OK, 1-号码只能由数字组成; 2-号码只能为11位; 3-号码必须以0或1开头

	if (![NSString isNumber: aString]) {
		return NO;
	}else if ([aString length] !=11) {
		return NO;
	}else if (!([[aString substringToIndex:1] isEqualToString:@"0"]||[[aString substringToIndex:1] isEqualToString:@"1"])) {
		return NO;
	}

	return YES;
}
-(BOOL)isMobileNumber{
    NSString *pattern = @"^(13[0-9]|15[0-9]|18[0-9])\\d{8}$";
    NSRegularExpression *regular = [[NSRegularExpression alloc] initWithPattern:pattern
                                                                        options:NSRegularExpressionCaseInsensitive 
                                                                          error:nil];
    NSInteger result = [regular numberOfMatchesInString:self options:NSMatchingReportProgress
                                                  range:NSMakeRange(0, self.length)];
    
    if (result > 0) {
        return YES;
    }
    return NO;
}

+(BOOL)isValidateEmail:(NSString *)email

{
    
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex];
    
    return [emailTest evaluateWithObject:email];
}

@end
